/*
 * ContactManager.hpp
 *
 *  Created on: Jan 25, 2015
 *      Author: wasp
 */

#ifndef DE_HEIMWEGHELDEN_USER_CONTACTMANAGER_HPP_
#define DE_HEIMWEGHELDEN_USER_CONTACTMANAGER_HPP_

#include <QtCore/QObject>
#include <QtSql/QtSql>
#include <bb/cascades/GroupDataModel>
#include <bb/pim/contacts/ContactService>
#include <bb/data/SqlConnection>

class ApplicationUI;
namespace de
{
    namespace heimweghelden
    {
        namespace user
        {
            class ContactManager : public QObject
            {
                Q_OBJECT
                Q_PROPERTY(bb::cascades::GroupDataModel *contacts READ contacts CONSTANT);
            public:
                ContactManager(QObject* parent = NULL);
                virtual ~ContactManager();
                Q_INVOKABLE void initContacts();
                //void bindModel(bb::cascades::GroupDataModel* m);
                bb::cascades::GroupDataModel* contacts() const;
                Q_INVOKABLE void contactFavouriteChanged(QString number, bool favourite);
            private:
                ApplicationUI* app;
                bb::pim::contacts::ContactService* _contactService;
                bb::cascades::GroupDataModel* _contacts;
                bb::data::SqlConnection* sqlConnection;
                QSqlDatabase database;
                void loadPhoneContacts();
                void initDb();
                QList<QVariantMap> checkListForHelden(QList<QVariantMap> input);
            private Q_SLOTS:
                Q_INVOKABLE void fillContactModel();
            };

        } /* namespace user */
    } /* namespace heimweghelden */
} /* namespace de */

#endif /* DE_HEIMWEGHELDEN_USER_CONTACTMANAGER_HPP_ */
